<template>
  <div>
    <a-table :columns="columns" :data="data">   
      <template #agree="{ record }">
        <a-button @click="agreeSubmit(record.cupId)">同意</a-button>
      </template>
      <template #reject="{ record }">
        <a-button @click="rejectSubmit(record.cupId)">驳回</a-button>
      </template>
    </a-table>
  </div>
</template>
    
  <script>
// import { reactive } from "vue";
import axios from "axios";
import { reactive, h } from 'vue';
import { IconSearch } from '@arco-design/web-vue/es/icon';

export default {
  data() {
    const columns = [
      {
        title: "ID",
        dataIndex: "cupId",
      },
      {
        title: "申请加入班级ID",
        dataIndex: "addClassid",
      },
      {
        title: "申请家长",
        dataIndex: "addUser",
      },
      {
        title: "处理情况",
        dataIndex: "supHandel",
      },
      {
        title: "同意",
        slotName: "agree",
      },
      {
        title: "驳回",
        slotName: "reject",
      },
    ];
    return {
      columns,
      data: [
        {
          cupId: 1,
          addClassid: "这是班级名称",
          addUser: "cac",
          supHandel: "未处理",
        },
      ],
      handle: "YES",
    };
  },
  methods: {
    agreeSubmit(key) {
      this.handle = "YES";
      this.handleAply(key);
      setTimeout(() => {
        this.searchInfo();
      }, 1000);
    },
    rejectSubmit(key) {
      this.handle = "NO";
      this.handleAply(key);
      setTimeout(() => {
        this.searchInfo();
      }, 1000);
    },
    handleAply(key) {
      axios
        .post("/submit/handleAddClass", {
          cupId: key,
          isHandel: this.handle,
        })
        .then((response) => {
          if (response.data) {
            alert("操作成功");
          } else {
            alert("操作失败");
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    searchInfo() {
      axios
        .get("/searchAddClassInfo")
        .then((response) => {
          this.data = response.data;
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
  created() {
    axios
      .get("/searchAddClassInfo")
      .then((response) => {
        this.data = response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
};
</script>

<style>
</style>
    